import java.io.*;
//import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

import db.DatabaseConnector;

public class ListResources extends HttpServlet {

//This subroutine is called by AddResC.asp
public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

	//The JSP document passes in which db table to use
	String tName = request.getParameter("tName");
	String actionStr = request.getParameter("action");

	//Variables for the database connection
	DatabaseConnector con = new DatabaseConnector(DatabaseConnector.getDatabaseType());;

	response.setContentType("text/html");
    	PrintWriter out = response.getWriter();

    try {
        //TODO: Query
        String SQL = "SELECT ID, Title, Abstract FROM " + tName;
        String[][] rs = con.selectSQL(SQL,3);
    
        out.print("<tr><td bgcolor=\"cccccc\"><b>Title</b></td>");
	out.print("<td bgcolor=\"cccccc\"><b>Description</b></td>");
	out.println("<td bgcolor=\"cccccc\"><b>" + actionStr + "</b></td></tr>");

        for (int i=0;i<rs.length;i++){
            if(rs[i][2].length() > 35) rs[i][2] = rs[i][2].substring(0, 35) + "...";
            out.print("<TR><TD>" + rs[i][1]);
            out.print("</TD><TD> " + rs[i][2]);
            out.print("</TD><TD><a href=\"" + actionStr + "Res.jsp?ID=" + rs[i][0] + "\">");
            out.println(actionStr + " Resource</a></td></tr>");
        }
    }
    finally
    {
        con.CleanUp();
    }
}
}
